package com.hq.zb.config;

import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * Mybatis-Plus配置
 *
 * @author huanghanrui
 * @date 2022-03-23
 */
@Configuration
@ConditionalOnClass(value = {PaginationInterceptor.class})
public class MybatisPlusConfig {

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    /**
     * 分页插件
     * @return
     */
	@Bean
	public PaginationInterceptor paginationInterceptor() {
		PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
		return paginationInterceptor;
	}

    /**
     * 自动填充
     */
    @PostConstruct
    public void addInterceptor(){
        sqlSessionFactory.getConfiguration().addInterceptor(new MybatisInterceptor());
    }
}
